\section{Spreadsheet technology}
\label{Spreadsheet technology}
\subsection{Introduction to spreadsheets}
The most popular spreadsheet application today is Microsoft Excel, but computerized spreadsheets as we know them today have been used since the first WYSIWYG\footnote{What You See Is What You Get} spreadsheet application, VisiCalc. It was developed for the Apple II computer by Dan Bricklin and Bob Frankston \cite{visicalc}. 

In common spreadsheet software a spreadsheet consists of a workbook that can contain up to several sheets. Each sheet has multiple cells that together create a grid consisting of rows and columns. Each cell can contain a text value, a number value or a formula. A formula describes how the value of the cell can be calculated from the values of other cells. When a cell is updated the value of all the cells referencing that cell will be recalculated. This ensures that the cells of the entire sheet automatically stay up to date.



\subsection{CoreCalc spreadsheet implementation}

In this thesis we base our prototype on CoreCalc \cite{sestoft}. CoreCalc is an open source implementation of core spreadsheet functionality in C\#. It is developed at the IT University of Copenhagen and is only intended as a platform for experiments with new technology and functionality. As the documentation states, it is not a replacement for Microsoft Excel, Gnumeric or Open Office Calc, but a research prototype.

It might have been possible to base our prototype on Open Office Calc or Gnumeric as they are both open source, but they are also far more complex and feature rich than CoreCalc. It might not have been possible to implement our prototype without rewriting parts of the spreadsheet engine. CoreCalc however is built as a platform for new experiments and it features sheet defined functions. Sheet defined functions are separate from the normal spreadsheet evaluation gives more possibilities for optimisations. Gnumerics or Open Office Calc does not have sheet defined functions.

\subsubsection{Spreadsheet programs}
Based on \textit{"A Spreadsheet Core Implementation in C\#"}\cite{sestoft} now follows an overview of how a spreadsheet program works.

Spreadsheet programs are dynamically typed functional programs that can be programmed by simple formulas in cells. Spreadsheets handle data types such as strings, numbers, logical expressions, and matrices, but they are handled dynamically. This makes formulas very dynamic and one can easily introduce an error such as \\$=SQRT(IF(A1<0; "Hello world" ; 25))$ that returns 5 if $A1>=0$ and otherwise returns an error because SQRT only takes a number as its argument.

Functional programming is a paradigm that is similar to the evaluation of mathematical functions. For example in the evaluation of spreadsheet cells it avoids states and mutable data. One cell cannot change the value of another cell if that cell is not somehow dependent on it. In functional languages you distinguish between strict (eager) and non-strict (lazy) evaluation. In eager evaluation all expressions is evaluated independently of whether they're used or not. In lazy evaluation an expression is only evaluated when there is a demand for it, and then cached so that other demands can use this cached value. In spreadsheets we have a similar concepts in that a cell is only evaluated when one of the cells it is referencing to is updated.

\subsubsection{Sheet defined functions}
CoreCalc introduces a new concept called Sheet Defined Functions (or SDF for short). Sheet defined functions allow spreadsheet users to define functions which can be used just like normal built-in function through the entire workbook.

\begin{figure}[H]
\includegraphics[width=1.0\textwidth]{pics/HeronParamRandom.png}
\caption{Herons Formula as a Sheet Defined Function in CoreCalc}
\label{sdf in corecalc}
\end{figure}

In fig. \ref{sdf in corecalc} Herons formula is implemented. The green cells are input cells that act as arguments for the function. The blue cell is the ouput cell, which is a formula that depends on the input cells. The user is able to use normal formulas and cell-references when defining the function. In this figure we have implemented Herons formula, with A4 and B4 as input cells, and the last side of the triangle simply calls a random function.

In CoreCalc, SDFs is compiled into .NET bytecode for optimised calculations.